package features.advance.jdk.io.unblocking;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.Set;

/**
 * @author LIN
 * @date 2021-07-09
 */
public class Client {

    public static void main(String[] args) throws Exception{
        SocketChannel channel = SocketChannel.open();
        channel.configureBlocking(false);
        SocketAddress socketAddress = InetSocketAddress.createUnresolved("localhost",8081);
        channel.connect(socketAddress);
        Selector selector = Selector.open();

        channel.register(selector, SelectionKey.OP_CONNECT);

        int nKeys = selector.select(3000);
        SelectionKey sKey = null;

        if (nKeys > 0){
            Set<SelectionKey> keys = selector.selectedKeys();
            for (SelectionKey key : keys) {


            }
        }

    }


}
